import { Profile, ProfileUser } from '@/types/data'
import { ProfileAction } from '@/types/store'
// 将来不只是 存储用户自己的信息 编辑的时候存储的个人信息等 所以使用到对象存储
type InitValueType = {
  user: ProfileUser
  userProfile: Profile
}
const initValue = {
  user: {},
  userProfile: {},
} as InitValueType
export default function profile(
  state = initValue,
  action: ProfileAction
): InitValueType {
  if (action.type === 'profile/getUser') {
    return {
      ...state,
      user: action.payload,
    }
  }
  if (action.type === 'profile/getUserProfile') {
    return {
      ...state,
      userProfile: action.payload,
    }
  }
  return state
}
